package ema.tpjee.utils.local;

import java.util.Hashtable;


/**
 * 
 * @author francois
 * simule un annuaire en local
 *
 */
public class AppLocator {

	private static AppLocator instance = new AppLocator();
	
	private static Hashtable<String, Object> directory = new Hashtable<String, Object>();

	public static AppLocator getInstance() {
		return instance;
	}

	public <T> T getComponent(String name) {
			T service = (T)directory.get(name);	
			if (service!=null){
				System.out.println("existing service found: "+name);
				return service;
			}
            try {
				service = (T)Class.forName(name).newInstance();
			} catch (Exception e) {
				e.printStackTrace();
			}
			directory.put(name, service);
			System.out.println("service created: "+name);
			return service;	
	}

}